
private ["_action_type","_current_height","_start_height","_target_height"];

_player = _this select 0;
_args = _this select 3;

_elevator = objNull;
_command = 0;
If (count _args > 0) then {_elevator = _args select 0;};
If (count _args > 1) then {_command = _args select 1;};

If (isNull _elevator) then {
	_elevator = nearestObject [_player,"Land_LHD_elev_R"];
};
If (isNull _elevator) exitwith {hintSilent Format["Elevator not found!"];};
sleep (0.5 + random 1.12);
_lhd_elevator_status = _elevator getVariable "Status";
if (isnil "_lhd_elevator_status") then {_lhd_elevator_status=0};
If (_lhd_elevator_status > 0) exitwith {diag_log Format["(%1)[%2]: %3",diag_tickTime,"lhdelevator.sqf","Already moving"];};
_elevator setVariable ["Status",1,true];

_start_height = _elevator getVariable "StartHeight";
_current_height = (getPosATL _elevator) select 2;
_target_height = _current_height;
If (_command == 0) then {
	// Lower the elevator
	_target_height = _start_height - 17;
	if (_current_height > (_start_height - 5)) then {_target_height = _start_height - 8;};
} else {
	// Raise the elevator
	_target_height = _start_height;
	if (_current_height < (_start_height - 10)) then {_target_height = _start_height - 8;};
};
diag_log Format["(%1)[%2]: %3 / %4 / %5",diag_tickTime,"lhdelevator.sqf",_this, _current_height, _target_height];

If (_current_height != _target_height) then {
	_step = 0.01;
	if (_current_height > _target_height) then {_step = -0.01};

	for "VARNAME" from _current_height to _target_height step _step do
	{
		_newPos = getPosATL _elevator;
		_newPos set [2, ((_newPos select 2) + _step)];
		_elevator setPosATL _newPos;
		sleep 0.01;
		if (abs((_newPos select 2) - _target_height) <= 0.01) exitWith {};
	};
};
diag_log Format["(%1)[%2]: %3: %4 / %5",diag_tickTime,"lhdelevator.sqf","Done moving", _current_height, _target_height];
_elevator setVariable ["Status",0,true];

